/*
    处理评论数据的逻辑
*/
const { sqlQuery } = require('../mysql/index')

module.exports = {
    addComment, getCommentList
}

//添加评论
async function addComment(data) {
    let blogId = data.blogId;
    let time = data.time;
    let name = data.name;
    let content = data.content;
    let head = data.head

    let sql = `insert into comment_data(blogId,content,time,name,head) values("${blogId}","${content}","${time}","${name}","${head}");`
    return new Promise(function (resolve, reject) {
        sqlQuery(sql, data => {
            resolve(data)
        })
    })
}

//获取评论列表
async function getCommentList(blogId) {
    let sql = `select * from comment_data where blogId=${blogId} ORDER BY time desc;`
    return new Promise(function (resolve, reject) {
        sqlQuery(sql, data => {
            resolve(data)
        })
    })
}